<?php
namespace Api\Controller;
use Think\Controller;

class AJAX extends Controller {
    /**
     * ajax返回：成功
     */
    public function success_return($data=null,$config=["code"=>200,"msg"=>"ok"] )
    {
        if($data){
            $this->ajaxReturn( ["status"=>true,"code"=>$config["code"],"msg"=>$config["msg"],"data"=>$data]);
        }else{
            $this->ajaxReturn( ["status"=>true,"code"=>$config["code"],"msg"=>$config["msg"]]);
        }
    }

    /**
     * ajax返回：失败
     */
    public function fail_return($code,$msg,$data=null)
    {
        if($data){
            $this->ajaxReturn( ["status"=>false,"code"=>$code,"msg"=>$msg,"data"=>$data]);
        }else{
            $this->ajaxReturn( ["status"=>false,"code"=>$code,"msg"=>$msg]);
        }
    }

}